/*******************************************************************************
FILENAME: PolEcon_of_CBReforms_ReplicationCode.do


Davide Romelli. 2022. romellid@tcd.ie.


This program creates all of the tables, figures, and numbers reported 
  in the text of:

  Romelli, Davide. "The Political Economy of Reforms in
	Central Bank Institutional Design: Evidence from a new dataset".
	Economic Policy, 2022.
  
Before running, follow the steps specified in README.pdf and 
  overwrite "/SPECIFY/LOCATION/OF/PARENT/DIRECTORY/HERE" in this file with
  the file path being used.
  	

This program is organized into the following sections:

  0. Clear data, define working directories and install packages
  1. Create figures
  2. Create summary statistics
  3. Create regression tables
  
*******************************************************************************/



********************************************************************************
********************************************************************************
*(0) Clear data, define working directories and install packages
********************************************************************************
********************************************************************************

* Clear data
clear all
clear matrix
clear mata
scalar drop _all
macro drop _all
set mem 2000m
set matsize 10000
set maxvar 10000
set more off

* Define working directories
*
* global dirroot = "/SPECIFY/LOCATION/OF/PARENT/DIRECTORY/HERE"
*
* Automatically assign main directory
dis "current user: `c(username)'"	// Provides the USERNAME of the computer on which Stata is running
if "`c(username)'" == "USERNAME1" {	// Add information on USERNAME1
global dirroot = "/Users/USERNAME/Dropbox/Romelli_EP_2022_ReplicationCode"	// Directory for Mac 
}
else if "`c(username)'" == "USERNAME2" {	// Add information on USERNAME2
global dirroot = "C:\Users\USERNAME2\Dropbox\Romelli_EP_2022_ReplicationCode"	// Directory for Windows
}
* 
global dirdta = "${dirroot}/dta"
global dirreg = "${dirroot}/results"
global dirfig = "${dirroot}/figures"
global dirspatial = "${dirroot}/SpatialData"

* Install packages
ssc install spmap
ssc install sutex2
ssc install pmat
ssc install xsmle


**********************
* LOCAL DEFINITIONS
*********************

local figures					= 1		// set this local = 1 if you intend to run this part of the cose
local stats						= 1
local regressions				= 1

cd "${dirroot}"
set more off



********************************************************************************
********************************************************************************
*(1) Create figures
********************************************************************************
********************************************************************************

if `figures' == 1 {

cd "${dirfig}"

************************************************
************************************************
*(1.1) Figure 1: Central Bank Independence around the world in 2017
************************************************
************************************************

* Open the WorldMap Data
use "${dirdta}/WorldMapCBIE-d.dta", clear
*
* Run the spmap code and save the figure
spmap  CBIE using "${dirdta}/WorldMapCBIE-c.dta" if admin!="Antarctica", id(id) fcolor(Blues) clnumber(16) legend(symy(*1) symx(*1) size(*1) label(2 "[0, 0.40)") label(3 "[0.40, 0.60)" ) label(4 "[0.60, 0.80)" )  label(5 "[0.80, 0.90)" ) label(6 "[0.90, 1]"))  ndlab("Missing data")  clme(custom) clb(0 0.40 0.60 0.80 0.90 1)
graph save Graph "Figure1.gph", replace
graph export "Figure1.eps", as(eps) preview(off) replace
graph export "Figure1.png", as(png) replace


************************************************
************************************************
*(1.2) Figure 2: Central Bank legislative reforms (1972-2017)
************************************************
************************************************

use "${dirdta}/PolEcon_of_CBReforms_Dataset", clear

bysort year: egen CBIE_Reversal_byYear=sum(CBIE_Reversal)
replace CBIE_Reversal_byYear=-CBIE_Reversal_byYear
bysort year: egen CBIE_Reform_byYear=sum(CBIE_Reform)
bysort year: egen CBIERef_byYear=sum(CBIERef)
gen CBIERef_byYear_Cum=CBIERef_byYear if year==1972
tsset
replace CBIERef_byYear_Cum=CBIERef_byYear+l.CBIERef_byYear_Cum if year!=1972
set scheme s2color
grstyle init
grstyle set plain, horizontal grid
twoway (bar CBIE_Reform_byYear CBIE_Reversal_byYear year, yscale(range(-5 (10)25) axis(1)) xlabel(1972 (5) 2017) xtitle("Year") ytitle("Number of reforms per year",  axis(1)) legend(label(1 "Reforms that increase CBIE") label(2 "Reforms that decrease CBIE")  label(3 "Cumulative number of reforms") rows(2) size(small))) (line  CBIERef_byYear_Cum year, yaxis(2) ytitle("",  axis(2)) lcolor(black) yscale(range(-73 (50)300) axis(2)) sort scheme(s1mono) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white)) 
graph export "Figure2.eps", as(eps) replace
graph export "Figure2.png", as(png) replace


************************************************
************************************************
*(1.3) Figure 3: Evolution of Central Bank Independence
************************************************
************************************************

use "${dirdta}/PolEcon_of_CBReforms_Dataset", clear

bysort wb_a3: egen FirstYear=min(year) if CBIE!=.
bysort wb_a3: egen LastYear=max(year) if CBIE!=.
bysort wb_a3: gen CBIEFirstYear=CBIE if FirstYear==year
bysort wb_a3: gen CBIELastYear=CBIE if LastYear==year
bysort wb_a3: egen CBIEBegin=max(CBIEFirstYear)
bysort wb_a3: egen CBIEEnd=max(CBIELastYear)
*
tw (scatter CBIEEnd CBIEBegin) (function y=x, range(0 1)), xlabel(0(0.1)1) ylabel(0(0.1)1) ytitle("Degree of CBI (Last available year)")  xtitle("Degree of CBI (First available year)") legend(off) scheme(s2mono)
graph export "Figure3.eps", as(eps) replace
graph export "Figure3.png", as(png) replace


************************************************
************************************************
*(1.4) Figure 4: Evolution of CBI by regions
************************************************
************************************************

use "${dirdta}/PolEcon_of_CBReforms_Dataset", clear

bysort year RegionalClustering_Acemoglu: egen CBIE_CR1_mean=mean(CBIE)

set scheme s2color
grstyle init
grstyle set plain, horizontal grid
tw (line CBIE_CR1_mean year if  wb_a3=="BEN", lwidth(thick) lpattern(dash)) (line CBIE_CR1_mean year if  wb_a3=="KHM", lwidth(thick)  lpattern(longdash_dot)) (line CBIE_CR1_mean year if year>=1991 & wb_a3=="ALB", lwidth(thick)  lpattern(dash_dot)) (line CBIE_CR1_mean year if  wb_a3=="ARG", lwidth(thick) lpattern(shortdash)) (line CBIE_CR1_mean year if  wb_a3=="AFG", lwidth(thick) lpattern(shortdash_dot)) (line CBIE_CR1_mean year if  wb_a3=="BGD", lwidth(thick) lpattern(longdash)) (line CBIE_CR1_mean year if  wb_a3=="AUS", lwidth(thick) lpattern(solid)), ylabel(0.3 (0.15) 0.80) ytitle("") xlabel(1972 (5) 2017) legend(label(1 "Africa") label(2 "East Asia & Pacific") label(3 "Europe & Central Asia") label(4 "Latin America & Caribb.") label(5 "Middle East & North Africa") label(6 "South Asia") label(7 "West Europe & other dev.") rows(4)) scheme(s1mono)
graph export "Figure4.eps", as(eps) replace
graph export "Figure4.png", as(png) replace


************************************************
************************************************
*(1.5) Figure 5: Evolution of CBI by subcategories (1972-2017)
************************************************
************************************************

use "${dirdta}/PolEcon_of_CBReforms_Dataset", clear

* Generate the average value of the CBIE subcategories for each year
bysort year: egen CBIEBoard_mean=mean(CBIEBoard)
bysort year: egen CBIEPolicy_mean=mean(CBIEPolicy)
bysort year: egen CBIEObj_mean=mean(CBIEObj)
bysort year: egen CBIELending_mean=mean(CBIELending)
bysort year: egen CBIEFinances_mean=mean(CBIEFinances)
bysort year: egen CBIEReport_mean=mean(CBIEReport)

set scheme s2color
grstyle init
grstyle set plain, horizontal grid
tw (line CBIEBoard_mean year, lwidth(thick)), ylabel(0.3 (0.15) 0.9, labsize(tiny)) ytitle("Degree of CBI [0;1]", size(small)) xlabel(1972 (10) 2012, labsize(tiny)) title("Board", size(small)) xtitle("") saving(Board, replace)
tw (line CBIEPolicy_mean year, lwidth(thick)), ylabel(0.3 (0.15) 0.9, labsize(tiny)) ytitle("") xlabel(1972 (10) 2012, labsize(tiny)) title("Monetary policy", size(small)) xtitle("") saving(Policy, replace)
tw (line CBIEObj_mean year, lwidth(thick)), ylabel(0.3 (0.15) 0.9, labsize(tiny)) ytitle("") xlabel(1972 (10) 2012, labsize(tiny)) title("Objectives", size(small)) xtitle("") saving(Obj, replace)
tw (line CBIELending_mean year, lwidth(thick)), ylabel(0.3 (0.15) 0.9, labsize(tiny)) ytitle("Degree of CBI [0;1]", size(small)) xlabel(1972 (10) 2012, labsize(tiny)) title("Lending to the government", size(small)) xtitle("") saving(Lending, replace)
tw (line CBIEFinances_mean year, lwidth(thick)), ylabel(0.3 (0.15) 0.9, labsize(tiny)) ytitle("") xlabel(1972 (10) 2012, labsize(tiny)) title("Financial independence", size(small)) xtitle("") saving(Finances, replace)
tw (line CBIEReport_mean year, lwidth(thick)), ylabel(0.3 (0.15) 0.9, labsize(tiny)) ytitle("") xlabel(1972 (10) 2012, labsize(tiny)) title("Reporting and disclosure", size(small)) xtitle("") saving(Report, replace)
gr combine Board.gph Policy.gph Obj.gph Lending.gph Finances.gph Report.gph, col(3) iscale(1) ycommon xcommon
graph export "Figure5.eps", as(eps) replace
graph export "Figure5.png", as(png) replace


************************************************
************************************************
*(1.6) Figure 7: Legislative reforms by subcategories (1972-2017)
************************************************
************************************************

use "${dirdta}/PolEcon_of_CBReforms_Dataset", clear

* Rename variables for their reshape
rename CBIEBoardRefNr CBIEFunctionRefNr1
rename CBIEPolicyRefNr CBIEFunctionRefNr2
rename CBIEObjRefNr CBIEFunctionRefNr3
rename CBIELendingRefNr CBIEFunctionRefNr4
rename CBIEFinancesRefNr CBIEFunctionRefNr5
rename CBIEReportRefNr CBIEFunctionRefNr6
*
g id=1
keep id CBIEFunctionRefNr*
keep if CBIEFunctionRefNr1!=.
duplicates drop CBIEFunctionRefNr*, force
reshape long CBIEFunctionRefNr, i(id) j(Code)
g Dimension=""
replace Dimension="Board" if Code==1
replace Dimension="Policy" if Code==2
replace Dimension="Objectives" if Code==3
replace Dimension="Lending" if Code==4
replace Dimension="Finances" if Code==5
replace Dimension="Reporting" if Code==6
*
set scheme s2color
grstyle init
grstyle set plain, horizontal grid
graph bar (max) CBIEFunctionRefNr, over(Dimension, sort(Code)) intensity(60)  legend(off) ytitle("Nr of Reforms") note("Source: Authors' calculations") blabel(total) graphregion(style(none) fcolor(white)) scheme(s2mono) legend(size(small)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white)
graph export "Figure7.eps", as(eps) replace
graph export "Figure7.png", as(png) replace


************************************************
************************************************
*(1.7) Online Appendix Figures from OnlineAppFigureC1 to OnlineAppFigureC6: Evolution of CBI by regions and subcategories (1972-2017)
************************************************
************************************************

use "${dirdta}/PolEcon_of_CBReforms_Dataset", clear

* Generate the average value of the CBIE subcategories for each year
bysort year RegionalClustering_Acemoglu: egen CBIEBoard_CR1_mean=mean(CBIEBoard)
bysort year RegionalClustering_Acemoglu: egen CBIEPolicy_CR1_mean=mean(CBIEPolicy)
bysort year RegionalClustering_Acemoglu: egen CBIEObj_CR1_mean=mean(CBIEObj)
bysort year RegionalClustering_Acemoglu: egen CBIELending_CR1_mean=mean(CBIELending)
bysort year RegionalClustering_Acemoglu: egen CBIEFinances_CR1_mean=mean(CBIEFinances)
bysort year RegionalClustering_Acemoglu: egen CBIEReport_CR1_mean=mean(CBIEReport)

set scheme s2color
grstyle init
grstyle set plain, horizontal grid
*
tw (line CBIEBoard_CR1_mean year if  wb_a3=="BEN", lwidth(thick) lpattern(dash)) (line CBIEBoard_CR1_mean year if  wb_a3=="KHM", lwidth(thick)  lpattern(longdash_dot)) (line CBIEBoard_CR1_mean year if year>=1991 & wb_a3=="ALB", lwidth(thick)  lpattern(dash_dot)) (line CBIEBoard_CR1_mean year if  wb_a3=="ARG", lwidth(thick) lpattern(shortdash)) (line CBIEBoard_CR1_mean year if  wb_a3=="AFG", lwidth(thick) lpattern(shortdash_dot)) (line CBIEBoard_CR1_mean year if  wb_a3=="BGD", lwidth(thick) lpattern(longdash)) (line CBIEBoard_CR1_mean year if  wb_a3=="AUS", lwidth(thick) lpattern(solid)), ylabel(0.3 (0.15) 0.9) ytitle("Degree of CBI [0;1]") xlabel(1972 (5) 2017) xtitle("") legend(label(1 "Africa") label(2 "East Asia & Pacific") label(3 "Europe & Central Asia") label(4 "Latin America & Caribb.") label(5 "Middle East & North Africa") label(6 "South Asia") label(7 "West Europe & other dev.") rows(4)) scheme(s1mono) saving(Board, replace)
graph export "OnlineAppFigureC1.eps", as(eps) replace
*
tw (line CBIEPolicy_CR1_mean year if  wb_a3=="BEN", lwidth(thick) lpattern(dash)) (line CBIEPolicy_CR1_mean year if  wb_a3=="KHM", lwidth(thick)  lpattern(longdash_dot)) (line CBIEPolicy_CR1_mean year if year>=1991 & wb_a3=="ALB", lwidth(thick)  lpattern(dash_dot)) (line CBIEPolicy_CR1_mean year if  wb_a3=="ARG", lwidth(thick) lpattern(shortdash)) (line CBIEPolicy_CR1_mean year if  wb_a3=="AFG", lwidth(thick) lpattern(shortdash_dot)) (line CBIEPolicy_CR1_mean year if  wb_a3=="BGD", lwidth(thick) lpattern(longdash)) (line CBIEPolicy_CR1_mean year if  wb_a3=="AUS", lwidth(thick) lpattern(solid)), ylabel(0.3 (0.15) 0.9) ytitle("Degree of CBI [0;1]") xlabel(1972 (5) 2017) xtitle("") legend(label(1 "Africa") label(2 "East Asia & Pacific") label(3 "Europe & Central Asia") label(4 "Latin America & Caribb.") label(5 "Middle East & North Africa") label(6 "South Asia") label(7 "West Europe & other dev.") rows(4)) scheme(s1mono) saving(Policy, replace)
graph export "OnlineAppFigureC2.eps", as(eps) replace
*
tw (line CBIEObj_CR1_mean year if  wb_a3=="BEN", lwidth(thick) lpattern(dash)) (line CBIEObj_CR1_mean year if  wb_a3=="KHM", lwidth(thick)  lpattern(longdash_dot)) (line CBIEObj_CR1_mean year if year>=1991 & wb_a3=="ALB", lwidth(thick)  lpattern(dash_dot)) (line CBIEObj_CR1_mean year if  wb_a3=="ARG", lwidth(thick) lpattern(shortdash)) (line CBIEObj_CR1_mean year if  wb_a3=="AFG", lwidth(thick) lpattern(shortdash_dot)) (line CBIEObj_CR1_mean year if  wb_a3=="BGD", lwidth(thick) lpattern(longdash)) (line CBIEObj_CR1_mean year if  wb_a3=="AUS", lwidth(thick) lpattern(solid)), ylabel(0.3 (0.15) 0.9) ytitle("Degree of CBI [0;1]") xlabel(1972 (5) 2017)  xtitle("") legend(label(1 "Africa") label(2 "East Asia & Pacific") label(3 "Europe & Central Asia") label(4 "Latin America & Caribb.") label(5 "Middle East & North Africa") label(6 "South Asia") label(7 "West Europe & other dev.") rows(4)) scheme(s1mono) saving(Obj, replace)
graph export "OnlineAppFigureC3.eps", as(eps) replace
*
tw (line CBIELending_CR1_mean year if  wb_a3=="BEN", lwidth(thick) lpattern(dash)) (line CBIELending_CR1_mean year if  wb_a3=="KHM", lwidth(thick)  lpattern(longdash_dot)) (line CBIELending_CR1_mean year if year>=1991 & wb_a3=="ALB", lwidth(thick)  lpattern(dash_dot)) (line CBIELending_CR1_mean year if  wb_a3=="ARG", lwidth(thick) lpattern(shortdash)) (line CBIELending_CR1_mean year if  wb_a3=="AFG", lwidth(thick) lpattern(shortdash_dot)) (line CBIELending_CR1_mean year if  wb_a3=="BGD", lwidth(thick) lpattern(longdash)) (line CBIELending_CR1_mean year if  wb_a3=="AUS", lwidth(thick) lpattern(solid)), ylabel(0.3 (0.15) 0.9) ytitle("Degree of CBI [0;1]") xlabel(1972 (5) 2017)  xtitle("") legend(label(1 "Africa") label(2 "East Asia & Pacific") label(3 "Europe & Central Asia") label(4 "Latin America & Caribb.") label(5 "Middle East & North Africa") label(6 "South Asia") label(7 "West Europe & other dev.") rows(4)) scheme(s1mono) saving(Lending, replace)
graph export "OnlineAppFigureC4.eps", as(eps) replace
*
tw (line CBIEFinances_CR1_mean year if  wb_a3=="BEN", lwidth(thick) lpattern(dash)) (line CBIEFinances_CR1_mean year if  wb_a3=="KHM", lwidth(thick)  lpattern(longdash_dot)) (line CBIEFinances_CR1_mean year if year>=1991 & wb_a3=="ALB", lwidth(thick)  lpattern(dash_dot)) (line CBIEFinances_CR1_mean year if  wb_a3=="ARG", lwidth(thick) lpattern(shortdash)) (line CBIEFinances_CR1_mean year if  wb_a3=="AFG", lwidth(thick) lpattern(shortdash_dot)) (line CBIEFinances_CR1_mean year if  wb_a3=="BGD", lwidth(thick) lpattern(longdash)) (line CBIEFinances_CR1_mean year if  wb_a3=="AUS", lwidth(thick) lpattern(solid)), ylabel(0.3 (0.15) 0.9) ytitle("Degree of CBI [0;1]") xlabel(1972 (5) 2017)  xtitle("") legend(label(1 "Africa") label(2 "East Asia & Pacific") label(3 "Europe & Central Asia") label(4 "Latin America & Caribb.") label(5 "Middle East & North Africa") label(6 "South Asia") label(7 "West Europe & other dev.") rows(4)) scheme(s1mono) saving(Finances, replace)
graph export "OnlineAppFigureC5.eps", as(eps) replace
*
tw (line CBIEReport_CR1_mean year if  wb_a3=="BEN", lwidth(thick) lpattern(dash)) (line CBIEReport_CR1_mean year if  wb_a3=="KHM", lwidth(thick)  lpattern(longdash_dot)) (line CBIEReport_CR1_mean year if year>=1991 & wb_a3=="ALB", lwidth(thick)  lpattern(dash_dot)) (line CBIEReport_CR1_mean year if  wb_a3=="ARG", lwidth(thick) lpattern(shortdash)) (line CBIEReport_CR1_mean year if  wb_a3=="AFG", lwidth(thick) lpattern(shortdash_dot)) (line CBIEReport_CR1_mean year if  wb_a3=="BGD", lwidth(thick) lpattern(longdash)) (line CBIEReport_CR1_mean year if  wb_a3=="AUS", lwidth(thick) lpattern(solid)), ylabel(0.3 (0.15) 0.9) ytitle("Degree of CBI [0;1]") xlabel(1972 (5) 2017)  xtitle("") legend(label(1 "Africa") label(2 "East Asia & Pacific") label(3 "Europe & Central Asia") label(4 "Latin America & Caribb.") label(5 "Middle East & North Africa") label(6 "South Asia") label(7 "West Europe & other dev.") rows(4)) scheme(s1mono) saving(Report, replace)
graph export "OnlineAppFigureC6.eps", as(eps) replace

}
// end figures



********************************************************************************
********************************************************************************
*(2) Create summary statistics table
********************************************************************************
********************************************************************************

use "${dirdta}/SummaryStatistics_Dataset", clear

if `stats' == 1 {

************************************************
************************************************
* Create Table B.2.: Summary Statistics
************************************************
************************************************

sutex2 CBIE CBIE_Variation CBIE_plus DCBIE_LargerRegMed_plus CBIE_minus DCBIE_LargerRegMed_minus CBIEBoard_Variation CBIEPolicy_Variation CBIEObj_Variation CBIELending_Variation CBIEFinances_Variation CBIEReport_Variation GMT_Variation LVAU_Variation CWNE_Variation CBIU_Variation CBIE_RC1_RegPressAvg sbc2y scc2y sdc2y inflationcrises20pct2y IMFPrograms2y IMFPrograms2y_random imfloan_2y CurrencyUnion_pre5y gvtchangeII GovernmentCrises polity2 democracy ddemocracy DNationalist LCBConstitution govfrac wgi_rl_3ymean RealGDPgr_10yma_dummy2ygr DLKOFEcGI LDebtToGDP Delta1yEconomicFreedom ReserveGDP, minmax varlab nocheck
 
}
// end stats



********************************************************************************
********************************************************************************
*(3) Create regression tables
********************************************************************************
********************************************************************************

if `regressions' == 1 {

cd "${dirreg}"
use "${dirdta}/PolEcon_of_CBReforms_Dataset", clear
tsset

************************************************
************************************************
*(3.1) Define the main variables and macros ;
************************************************
************************************************

* Create and label additional variables
g DCBI=.
la var DCBI "$\Delta$ CBI"
g CBI_StatQuoBias=.
la var CBI_StatQuoBias "Status quo"
g CBI_RegPressure=.
la var CBI_RegPressure "Regional pressure" 
g CBI=.
la var CBI "Status quo"
g LCBI=.
la var LCBI "CBI$ _{i,t-1}$"
g CBIsq=.
la var CBIsq "CBI$ _{i,t}^2$"
g LCBIsq=.
la var LCBIsq "CBI$ _{i,t-1}^2$"
g CBIReform=.
la var CBIReform "CBI CBIReform$ _{i,t}$"
g Polity=Lpolity2
la var Polity "Polity{sub:t-1}"
g DLKOFEcGI=d.l.KOFEcGI
la var DLKOFEcGI "$\Delta$ Econ. Globalization$ _{i,t-1}$"
g LCBConstitution=l.CBinConstitution_IndepOrganiz
la var LCBConstitution "Constitution$ _{i,t-1}$"
g LDebtToGDP=l.DebtToGDP
la var LDebtToGDP "Debt to GDP$ _{i,t-1}$"
* Create a dummy variable summarising all types of crises
g crisis2y=0
replace crisis2y=sbc2y
replace crisis2y=1 if scc2y==1 & crisis2y==0
replace crisis2y=1 if sdc2y==1 & crisis2y==0
replace crisis2y=1 if inflationcrises20pct2y==1 & crisis2y==0
* Create dummies for Reforms and Reversals in CBI
g CBIE_plus=0 if CBIE!=.
replace CBIE_plus=1 if d.CBIE>0 & CBIE!=. & l.CBIE!=.
g CBIE_minus=0 if CBIE!=.
replace CBIE_minus=1 if d.CBIE<0 & CBIE!=. & l.CBIE!=.
g CBIEBis_plus=0 if CBIEBis!=.
replace CBIEBis_plus=1 if d.CBIEBis>0 & CBIEBis!=. & l.CBIEBis!=.
g CBIEBis_minus=0 if CBIEBis!=.
replace CBIEBis_minus=1 if d.CBIEBis<0 & CBIEBis!=. & l.CBIEBis!=.
* Create dummies for reforms > median/mean value at the regional level
tsset
g DCBIE=d.CBIE
bysort RegionalClustering_Acemoglu: egen DCBIE_RegMed_positive=median(DCBIE) if DCBIE>0 & DCBIE!=.
bysort RegionalClustering_Acemoglu: egen DCBIE_RegMed_negative=median(DCBIE) if DCBIE<0 & DCBIE!=.
tsset
g DCBIE_LargerRegMed_plus=1 if d.CBIE>=DCBIE_RegMed_positive 
replace DCBIE_LargerRegMed_plus=. if d.CBIE==.
replace DCBIE_LargerRegMed_plus=0 if d.CBIE!=. & DCBIE_LargerRegMed_plus!=1
g DCBIE_LargerRegMed_minus=1 if d.CBIE<=DCBIE_RegMed_negative & DCBIE_RegMed_negative!=.
replace DCBIE_LargerRegMed_minus=0 if d.CBIE!=. & DCBIE_LargerRegMed_minus!=1
sum DCBIE_LargerRegMed_minus
* Create dummies for reforms > median/mean value at the regional level - CBIE Restricted index
tsset
g DCBIEBis=d.CBIEBis
bysort RegionalClustering_Acemoglu: egen DCBIEBis_RegMed_positive=median(DCBIEBis) if DCBIEBis>0 & DCBIEBis!=.
bysort RegionalClustering_Acemoglu: egen DCBIEBis_RegMed_negative=median(DCBIEBis) if DCBIEBis<0 & DCBIEBis!=.
tsset
g DCBIEBis_LargerRegMed_plus=1 if d.CBIEBis>=DCBIEBis_RegMed_positive 
replace DCBIEBis_LargerRegMed_plus=. if d.CBIEBis==.
sum DCBIEBis_LargerRegMed_plus
replace DCBIEBis_LargerRegMed_plus=0 if d.CBIEBis!=. & DCBIEBis_LargerRegMed_plus!=1
g DCBIEBis_LargerRegMed_minus=1 if d.CBIEBis<=DCBIEBis_RegMed_negative & DCBIEBis_RegMed_negative!=.
replace DCBIEBis_LargerRegMed_minus=0 if d.CBIEBis!=. & DCBIEBis_LargerRegMed_minus!=1
sum DCBIEBis_LargerRegMed_minus

* Define global macros
global c_id = "Country_id"
global dcbi = "DCBI"
global cbi = "CBI"
global cbisq = "CBIsq"
global statquo = "CBI_StatQuoBias"
global regpress = "CBI_RegPressure"
global cbiref = "CBIReform"
global imf = "IMFPrograms2y"
global cu = "CurrencyUnion_pre5y"
global crises = "sbc2y scc2y sdc2y inflationcrises20pct2y"
global pol = "gvtchangeII GovernmentCrises Lpolity2 LCBConstitution govfrac"
global pol_nopolity = "gvtchangeII GovernmentCrises LCBConstitution govfrac"
global econ = "RealGDPgr_10yma_dummy2ygr DLKOFEcGI LDebtToGDP"
global econ_nokof = "RealGDPgr_10yma_dummy2ygr LDebtToGDP"
global imf_random = "IMFPrograms2y_random"
global drop = "cut1 cut2 cut3 cut4 cut5 cut6 cut7 cut8 cut9 cut10 cut11 cut12 cut13 cut14 cut15 cut16 cut17 cut18 cut19 cut20 cut21 cut22 cut23 cut24 cut25 cut26 cut27 cut28 cut29 cut30 cut31 cut32 cut33 cut34 cut35 cut36 cut37 cut38 cut39 cut40 cut41 cut42 cut43 cut44 cut45 cut46 cut47 cut48 cut46 cut47 cut48 cut49 cut50 cut51 cut52 cut53 cut54 cut55 cut56 cut57 cut58 cut59 cut60 cut61 cut62 cut63 cut64 cut65 cut66 cut67 cut68 cut69 cut70 cut71 cut72 cut73 cut74 cut75 cut76 cut77 cut78 cut79 cut80 sigma2_u lnsig2u"


************************************************
************************************************
*(3.2) Create Table 3: Drivers of reforms in central bank design
************************************************
************************************************

replace DCBI=CBIE_Variation
replace CBI=l.CBIE
replace CBI_RegPressure=l.CBIE_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu i.year, cluster($c_id) fe
outreg2 using "Table3.tex", ctitle(Full sample) bdec(3) tdec(3) nonot nocons nodepvar se replace tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
xtreg $dcbi $cbi $regpress $imf $cu $crises i.year, cluster($c_id) fe
outreg2 using "Table3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "Table3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year if oecd==1, cluster($c_id) fe
outreg2 using "Table3.tex", ctitle(Advanced) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year if oecd!=1, cluster($c_id) fe
outreg2 using "Table3.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ) sortvar($dcbi $cbi $regpress $imf $cu $crises $pol $econ)


************************************************
************************************************
*(3.3) Create Figure 6: Sign and magnitude of reforms
************************************************
************************************************

replace CBI=l.CBIE
replace CBI_RegPressure=l.CBIE_RC1_RegPressAvg
replace CBIReform=CBIE_plus
cloglog $cbiref $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id
estimates store Positive
outreg2 using "OnlineAppTableD1.tex", ctitle(Reform) bdec(3) tdec(3) nonot nocons se replace tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbiref $statquo $cbi $cbisq $regpress $imf $cu $crises $pol $econ)
replace CBIReform=DCBIE_LargerRegMed_plus
cloglog $cbiref $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id
estimates store LargePositive
outreg2 using "OnlineAppTableD1.tex", ctitle(Large Reform) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbiref $statquo $cbi $cbisq $regpress $imf $cu $crises $pol $econ)
replace CBIReform=CBIE_minus
cloglog $cbiref $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id
estimates store Negative
outreg2 using "OnlineAppTableD1.tex", ctitle(Reversal) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbiref $statquo $cbi $cbisq $regpress $imf $cu $crises $pol $econ)
replace CBIReform=DCBIE_LargerRegMed_minus
cloglog $cbiref $cbi $regpress $imf $cu $crises gvtchangeII GovernmentCrises Lpolity2 govfrac $econ i.year i.$c_id
estimates store LargeNegative
outreg2 using "OnlineAppTableD1.tex", ctitle(Large Reversal) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbiref $statquo $cbi $cbisq $regpress $imf $cu $crises $pol $econ)

set scheme s2color
grstyle init
grstyle set plain, horizontal grid
coefplot (Positive, label(Reform) msymbol(O)) (LargePositive, label(Large Reform) msymbol(Oh) xscale(range(-20 35))) (Negative, label(Reversal) msymbol(S)) (LargeNegative, label(Large Reversal) msymbol(Sh)), keep($cbi $regpress $pol) xline(0) ci(90) byopts(xrescale cols(4)) coeflabels(Lpolity2 = "Polity{sub:t-1}" DLKOFEcGI = "{&Delta}Econ. Globalization{sub:t-1}" LDebtToGDP = "Debt to GDP{sub:t-1}" LCBConstitution = "Constitution{sub:t-1}" gvtchangeII = "Cabinet change" govfrac = "Gvt Fractionalization", labsize(small)) graphregion(style(none) fcolor(white)) scheme(s2mono) legend(cols(4) size(small)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) saving(cbi, replace) 
coefplot (Positive, msymbol(O)) (LargePositive, msymbol(Oh)) (Negative, msymbol(S)) (LargeNegative, msymbol(Sh)), keep($imf $crises $econ) xline(0) ci(90) byopts(xrescale cols(4)) coeflabels(Lpolity2 = "Polity{sub:t-1}" DLKOFEcGI = "{&Delta}Econ. Globalization{sub:t-1}" LDebtToGDP = "Debt to GDP{sub:t-1}" LCBConstitution = "Constitution{sub:t-1}" gvtchangeII = "Cabinet change" govfrac = "Gvt Fractionalization", labsize(small)) graphregion(style(none) fcolor(white)) scheme(s2mono) legend(size(small)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) saving(imf, replace)
grc1leg cbi.gph imf.gph, legendfrom(cbi.gph)
graph export "${dirfig}/Figure6.eps", as(eps) replace


************************************************
************************************************
*(3.4) Create Table 4: Sign and magnitude of reforms
************************************************
************************************************

replace DCBI=CBIEBoard_Variation
replace CBI=l.CBIEBoard
replace CBI_RegPressure=l.CBIEBoard_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "Table4.tex", ctitle($\Delta$ Board) bdec(3) tdec(3) nonot nocons se replace tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
replace DCBI=CBIEPolicy_Variation
replace CBI=l.CBIEPolicy
replace CBI_RegPressure=l.CBIEPolicy_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "Table4.tex", ctitle($\Delta$ Mon. Policy) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
replace DCBI=CBIEObj_Variation
replace CBI=l.CBIEObj
replace CBI_RegPressure=l.CBIEObj_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "Table4.tex", ctitle($\Delta$ Objectives) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
replace DCBI=CBIELending_Variation
replace CBI=l.CBIELending
replace CBI_RegPressure=l.CBIELending_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "Table4.tex", ctitle($\Delta$ Lending) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
replace DCBI=CBIEFinances_Variation
replace CBI=l.CBIEFinances
replace CBI_RegPressure=l.CBIEFinances_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "Table4.tex", ctitle($\Delta$ Financial Ind.) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
replace DCBI=CBIEReport_Variation
replace CBI=l.CBIEReport
replace CBI_RegPressure=l.CBIEReport_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "Table4.tex", ctitle($\Delta$ Report \& Acc.) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ) sortvar($cbiref $dcbi $statquo $cbi $regpress $imf $cu $crises $pol $econ)


************************************************
************************************************
*(3.5) Create Table 5: Central bank design and democracy
************************************************
************************************************

replace DCBI=CBIE_Variation
replace CBI=l.CBIE
replace CBI_RegPressure=l.CBIE_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol_nopolity $econ democracy i.year, cluster($c_id) fe
outreg2 using "Table5.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se replace tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $statquo $cbi $regpress $imf $cu $crises $pol_nopolity $econ democracy)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol_nopolity $econ democracy i.year if oecd==0, cluster($c_id) fe
outreg2 using "Table5.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $statquo $cbi $regpress $imf $cu $crises $pol_nopolity $econ democracy)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol_nopolity $econ ddemocracy i.year, cluster($c_id) fe
outreg2 using "Table5.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $statquo $cbi $regpress $imf $cu $crises $pol_nopolity $econ ddemocracy)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol_nopolity $econ ddemocracy i.year if oecd==0, cluster($c_id) fe
outreg2 using "Table5.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $statquo $cbi $regpress $imf $cu $crises $pol_nopolity $econ ddemocracy)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol_nopolity $econ DNationalist i.year if polity2!=., cluster($c_id) fe
outreg2 using "Table5.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $statquo $cbi $regpress $imf $cu $crises $pol_nopolity $econ DNationalist)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol_nopolity $econ DNationalist i.year if oecd==0 & polity2!=., cluster($c_id) fe
outreg2 using "Table5.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $statquo $cbi $regpress $imf $cu $crises $pol_nopolity $econ DNationalist) sortvar($cbiref $dcbi $statquo $cbi $regpress $imf $cu $crises $pol_nopolity democracy ddemocracy DNationalist $econ)


************************************************
************************************************
*(3.6) Create Figure C.1: Drivers of reform: robustness with alternative weights on the CBIE index
************************************************
************************************************

replace DCBI=CBIEPCA_Variation
replace CBI=l.CBIEPCA
replace CBI_RegPressure=l.CBIEPCA_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
estimates store PCA
replace DCBI=CBIEW_Variation
replace CBI=l.CBIEW
replace CBI_RegPressure=l.CBIEW_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
estimates store W

set scheme s2color
grstyle init
grstyle set plain, horizontal grid
coefplot (PCA, label(PCA Index) msymbol(O)) (W, label(Weighted Index) msymbol(S)), bylabel(Overall sample)||, keep($cbi $regpress $imf $cu $crises $pol $econ) xline(0) ci(90) coeflabels(Lpolity2 = "Polity{sub:t-1}" DLKOFEcGI = "{&Delta}Econ. Globalization{sub:t-1}" LDebtToGDP = "Debt to GDP{sub:t-1}" LCBConstitution = "Constitution{sub:t-1}" gvtchangeII = "Cabinet change" govfrac = "Gvt Fractionalization", labsize(small)) graphregion(style(none) fcolor(white)) scheme(s2mono) legend(size(small)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) 
graph export "${dirfig}/AppFigureC1.eps", as(eps) replace


************************************************
************************************************
*(3.7) Create Table C.3: Drivers of reforms: robustness using restricted versions of the CBIE index
************************************************
************************************************

replace DCBI=CBIEBis_Variation
replace CBI=l.CBIEBis
replace CBI_RegPressure=l.CBIEBis_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "AppTableC3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se replace tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year if oecd==1, cluster($c_id) fe
outreg2 using "AppTableC3.tex", ctitle(Advanced) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year if oecd!=1, cluster($c_id) fe
outreg2 using "AppTableC3.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ) sortvar($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
replace DCBI=CBIE_nosup_Variation
replace CBI=l.CBIE_nosup
replace CBI_RegPressure=l.CBIE_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "AppTableC3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year if oecd==1, cluster($c_id) fe
outreg2 using "AppTableC3.tex", ctitle(Advanced) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year if oecd!=1, cluster($c_id) fe
outreg2 using "AppTableC3.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ) sortvar($dcbi $cbi $regpress $imf $cu $crises $pol $econ)


************************************************
************************************************
*(3.8) Create Table C.4: Drivers of reforms: robustness using alternative CBI indices
************************************************
************************************************

replace DCBI=GMT_Variation
replace CBI=l.GMT
replace CBI_RegPressure=l.GMT_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "AppTableC4.tex", bdec(3) tdec(3) nonot nocons nodepvar se replace tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $statquo $cbi $regpress $imf $cu $crises $pol $econ)
replace DCBI=LVAU_Variation
replace CBI=l.LVAU
replace CBI_RegPressure=l.LVAU_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "AppTableC4.tex", bdec(3) tdec(3) nonot nocons nodepvar se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $statquo $cbi $regpress $imf $cu $crises $pol $econ)
replace DCBI=CWNE_Variation
replace CBI=l.CWNE
replace CBI_RegPressure=l.CWNE_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "AppTableC4.tex", bdec(3) tdec(3) nonot nocons nodepvar se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $statquo $cbi $regpress $imf $cu $crises $pol $econ)
replace DCBI=CBIU_Variation
replace CBI=l.CBIU
replace CBI_RegPressure=l.CBIU_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "AppTableC4.tex", bdec(3) tdec(3) nonot nocons nodepvar se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $statquo $cbi $regpress $imf $cu $crises $pol $econ) sortvar($dcbi $statquo $cbi $regpress $imf $cu $crises $pol $econ)


************************************************
************************************************
*(3.9) Create Table C.5: Drivers of reforms in central bank design: robustness with interaction terms
************************************************
************************************************

replace DCBI=CBIE_Variation
replace CBI=l.CBIE
replace CBI_RegPressure=l.CBIE_RC1_RegPressAvg
// Interaction with CBIE
xtreg $dcbi c.$cbi##(c.$regpress i.$imf i.$cu) i.year, cluster($c_id) fe
outreg2 using "AppTableC5.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons nodepvar se replace tex(fragment) lab eqdrop(i.year i.$c_id _cons) keep($cbi $regpress $imf $cu c.$cbi##c.$regpress c.$cbi##i.$imf c.$cbi##i.$cu $crises $cu $pol $econ)
xtreg $dcbi c.$cbi##(c.$regpress i.$imf i.$cu) $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "AppTableC5.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbi $regpress $imf $cu c.$cbi##c.$regpress c.$cbi##i.$imf c.$cbi##i.$cu $crises $cu $pol $econ)
xtreg $dcbi c.$cbi##(c.$regpress i.$imf i.$cu) $crises $pol $econ i.year if oecd!=1, cluster($c_id) fe
outreg2 using "AppTableC5.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbi $regpress $imf $cu c.$cbi##c.$regpress c.$cbi##i.$imf c.$cbi##i.$cu $crises $cu $pol $econ) sortvar($dcbi $cbi $regpress c.$cbi##c.$regpress $imf c.$cbi##i.$imf $cu c.$cbi##i.$cu $crises $pol $econ)
// Interaction with Polity
xtreg $dcbi c.Lpolity2##(c.$cbi c.$regpress i.$imf i.$cu) i.year, cluster($c_id) fe
outreg2 using "AppTableC5.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons nodepvar se tex(fragment) lab eqdrop(i.year i.$c_id _cons) keep($cbi $regpress $imf $cu c.Lpolity2##c.$cbi c.Lpolity2##c.$regpress c.Lpolity2##i.$imf $cu c.Lpolity2##i.$cu $crises $pol $econ)
xtreg $dcbi c.Lpolity2##(c.$cbi c.$regpress i.$imf i.$cu) $crises $pol $econ i.year, cluster($c_id) fe
outreg2 using "AppTableC5.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbi $regpress $imf $cu c.Lpolity2##c.$cbi c.Lpolity2##c.$regpress c.Lpolity2##i.$imf $cu c.Lpolity2##i.$cu $crises $pol $econ)
xtreg $dcbi c.Lpolity2##(c.$cbi c.$regpress i.$imf i.$cu) $crises $pol $econ i.year if oecd!=1, cluster($c_id) fe
outreg2 using "AppTableC5.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbi $regpress $imf $cu c.Lpolity2##c.$cbi c.Lpolity2##c.$regpress c.Lpolity2##i.$imf $cu c.Lpolity2##i.$cu $crises $pol $econ) sortvar($dcbi $cbi c.Lpolity2##c.$cbi $regpress c.Lpolity2##c.$regpress $imf c.Lpolity2##i.$imf $cu c.Lpolity2##i.$cu $crises $pol $econ)


************************************************
************************************************
*(3.10) Create Table C.6: Drivers of reforms in central bank design: size of IMF Loan to GDP
************************************************
************************************************

replace DCBI=CBIE_Variation
replace CBI=l.CBIE
replace CBI_RegPressure=l.CBIE_RC1_RegPressAvg
xtreg $dcbi $cbi $crises $regpress imfloan_2y $cu $pol $econ i.year, cluster($c_id) fe
outreg2 using "AppTableC6.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se replace tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbi $crises $regpress imfloan_2y $cu $pol $econ)
xtreg $dcbi $cbi $crises $regpress imfloan_2y $cu $pol $econ i.year if oecd==0, cluster($c_id) fe
outreg2 using "AppTableC6.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbi $crises $regpress imfloan_2y $cu $pol $econ)
xtreg $dcbi $cbi $crises $regpress $imf_random $cu $pol $econ i.year, cluster($c_id) fe
outreg2 using "AppTableC6.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons nodepvar se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $crises $regpress $imf $imf_random $cu $pol $econ)
xtreg $dcbi $cbi $crises $regpress $imf_random $cu $pol $econ i.year if oecd!=1, cluster($c_id) fe
outreg2 using "AppTableC6.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $crises $regpress $imf $imf_random $cu $pol $econ) sortvar($dcbi $cbi $regpress $imf $imf_random $crises $cu $pol $econ)


************************************************
************************************************
*(3.10) Create Figure C.2: Additional control variables
************************************************
************************************************

replace DCBI=CBIE_Variation
replace CBI=l.CBIE
replace CBI_RegPressure=l.CBIE_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ Delta1yEconomicFreedom wgi_rl_3ymean ReserveGDP i.year, cluster($c_id) fe
estimates store full
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ Delta1yEconomicFreedom wgi_rl_3ymean ReserveGDP i.year if oecd!=1, cluster($c_id) fe
estimates store dev
xtreg $dcbi $cbi $regpress $imf $crises $pol $econ Delta1yEconomicFreedom wgi_rl_3ymean ReserveGDP i.year if euroarea92!=1, cluster($c_id) fe
estimates store noeuro

set scheme s2color
grstyle init
grstyle set plain, horizontal grid
coefplot (full, label(Full sample) msymbol(O)) (dev, label(Developing) msymbol(Oh)) (noeuro, label(No Euro area) msymbol(S)), keep($cbi $regpress $pol wgi_rl_3ymean) xline(0) ci(90) byopts(xrescale cols(4)) coeflabels(Lpolity2 = "Polity{sub:t-1}" DLKOFEcGI = "{&Delta}Econ. Globalization{sub:t-1}" LDebtToGDP = "Debt to GDP{sub:t-1}" LCBConstitution = "Constitution{sub:t-1}" gvtchangeII = "Cabinet change" govfrac = "Gvt Fractionalization" wgi_rl_3ymean = "Rule of law" Delta1yEconomicFreedom="{&Delta} Economic Freedom" ReserveGDP = "Reserves to GDP", labsize(small)) graphregion(style(none) fcolor(white)) scheme(s2mono) legend(cols(4) size(small)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) saving(one, replace) 
coefplot (full, msymbol(O)) (dev, msymbol(Oh)) (noeuro, msymbol(S)), keep($imf $cu $crises $econ Delta1yEconomicFreedom ReserveGDP) xline(0) ci(90) byopts(xrescale cols(4)) coeflabels(Lpolity2 = "Polity{sub:t-1}" DLKOFEcGI = "{&Delta}Econ. Globalization{sub:t-1}" LDebtToGDP = "Debt to GDP{sub:t-1}" LCBConstitution = "Constitution{sub:t-1}" gvtchangeII = "Cabinet change" govfrac = "Gvt Fractionalization" wgi_rl_3ymean = "Rule of law" Delta1yEconomicFreedom="{&Delta} Economic Freedom" ReserveGDP = "Reserves to GDP", labsize(small)) graphregion(style(none) fcolor(white)) scheme(s2mono) legend(size(small)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) saving(two, replace)
grc1leg one.gph two.gph, legendfrom(one.gph)
graph export "${dirfig}/AppFigureC2.eps", as(eps) replace


************************************************
************************************************
*(3.11) Create Table C.8: Drivers of reforms in central bank design: logit and cloglog estimations
************************************************
************************************************

replace DCBI=CBIERef
replace CBI=l.CBIE
replace CBI_RegPressure=l.CBIE_RC1_RegPressAvg
logit $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id
outreg2 using "AppTableC8.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se replace tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
logit $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id if oecd==1
outreg2 using "AppTableC8.tex", ctitle(Advanced) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
logit $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id if oecd!=1
outreg2 using "AppTableC8.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
cloglog $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id
outreg2 using "AppTableC8.tex", ctitle("") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
cloglog $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id if oecd==1
outreg2 using "AppTableC8.tex", ctitle(Advanced) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ)
cloglog $dcbi $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id if oecd!=1
outreg2 using "AppTableC8.tex", ctitle(Developing) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ) sortvar($dcbi $cbi $regpress $imf $cu $crises $pol $econ)


************************************************
************************************************
*(3.11) Create Table OnlineApp.D.2: Sign and magnitude of reforms - Restricted index
************************************************
************************************************

replace CBI=l.CBIEBis
replace CBI_RegPressure=l.CBIEBis_RC1_RegPressAvg
replace CBIReform=CBIEBis_plus
cloglog $cbiref $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id
outreg2 using "OnlineAppTableD2.tex", ctitle(Reform) bdec(3) tdec(3) nonot nocons se replace tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbiref $statquo $cbi $cbisq $regpress $imf $cu $crises $pol $econ)
replace CBIReform=DCBIEBis_LargerRegMed_plus
cloglog $cbiref $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id
outreg2 using "OnlineAppTableD2.tex", ctitle(Large Reform) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbiref $statquo $cbi $cbisq $regpress $imf $cu $crises $pol $econ)
replace CBIReform=CBIEBis_minus
cloglog $cbiref $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id
outreg2 using "OnlineAppTableD2.tex", ctitle(Reversal) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbiref $statquo $cbi $cbisq $regpress $imf $cu $crises $pol $econ)
replace CBIReform=DCBIEBis_LargerRegMed_minus
cloglog $cbiref $cbi $regpress $imf $cu $crises $pol $econ i.year i.$c_id
outreg2 using "OnlineAppTableD2.tex", ctitle(Large Reversal) bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($cbiref $statquo $cbi $cbisq $regpress $imf $cu $crises $pol $econ)


************************************************
************************************************
*(3.12) Create Table OnlineApp.D.3:  Drivers of reforms in central bank design - Alternative measures ofthe Globalisation index
************************************************
************************************************

replace DCBI=CBIE_Variation
replace CBI=l.CBIE
replace CBI_RegPressure=l.CBIE_RC1_RegPressAvg
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFGI i.year, cluster($c_id) fe
outreg2 using "OnlineAppTableD3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se replace tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFGI)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFTrGI i.year, cluster($c_id) fe
outreg2 using "OnlineAppTableD3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFTrGI)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFFiGI i.year, cluster($c_id) fe
outreg2 using "OnlineAppTableD3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFFiGI)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFSoGI i.year, cluster($c_id) fe
outreg2 using "OnlineAppTableD3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFSoGI)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFIpGI i.year, cluster($c_id) fe
outreg2 using "OnlineAppTableD3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFIpGI)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFInGI i.year, cluster($c_id) fe
outreg2 using "OnlineAppTableD3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFInGI)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFCuGI i.year, cluster($c_id) fe
outreg2 using "OnlineAppTableD3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFCuGI)
xtreg $dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFPoGI i.year, cluster($c_id) fe
outreg2 using "OnlineAppTableD3.tex", ctitle(" ") bdec(3) tdec(3) nonot nocons se tex(fragment) lab eqdrop(i.year i.$c_id) keep($dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFPoGI) sortvar($dcbi $cbi $regpress $imf $cu $crises $pol $econ_nokof d.l.KOFGI d.l.KOFTrGI d.l.KOFFiGI d.l.KOFSoGI d.l.KOFIpGI d.l.KOFInGI d.l.KOFCuGI d.l.KOFPoGI)


************************************************
************************************************
*(3.13) Create Table C.7: Drivers of reforms in a dynamic spatial panel estimation
************************************************
************************************************

cd "${dirspatial}"
*
** Create the spmat object for an inverse distance
*
use country_balanced, clear
*
* Normalized matrix (where the max distance is set at 2000km)
spmat idistance dcountry2000 longitude latitude, id(id) dfunction(dhaversine) normalize(minmax) vtruncate(1/2000) replace
spmat summarize dcountry2000
*
** Attach a note to the spmat object ccounty and then display it
*
spmat note dcountry2000 : "Source: Davide Romelli country files."
spmat note dcountry2000
spmat save dcountry2000 using dcountry2000.spmat, replace
*
* Normalized matrix (where the max distance is set at 4000km)
spmat idistance dcountry4000 longitude latitude, id(id) dfunction(dhaversine) normalize(minmax) vtruncate(1/4000) replace
spmat summarize dcountry4000
*
** Attach a note to the spmat object ccounty and then display it
*
spmat note dcountry4000 : "Source: Davide Romelli country files."
spmat note dcountry4000
spmat save dcountry4000 using dcountry4000.spmat, replace

*
* Normalized matrix (where the max distance is set at 6000km)
spmat idistance dcountry6000 longitude latitude, id(id) dfunction(dhaversine) normalize(minmax) vtruncate(1/6000) replace
spmat summarize dcountry6000
*
** Attach a note to the spmat object ccounty and then display it
*
spmat note dcountry6000 : "Source: Davide Romelli country files."
spmat note dcountry6000
spmat save dcountry6000 using dcountry6000.spmat, replace
*
use "${dirdta}/SpatialEstimations_Dataset", clear
*
xsmle CBIE IMFPrograms2y CurrencyUnion_pre5y sbc2y scc2y sdc2y inflationcrises20pct2y, wmat(dcountry2000) model(sdm) fe durbin(CBIE) dlag(3) time
outreg2 using "${dirreg}/AppTableC7.tex", bdec(3) se replace tex(fragment) lab
test [Main]L.WCBIE+[Main]L.CBIE+[Wx]CBIE=1
xsmle CBIE IMFPrograms2y CurrencyUnion_pre5y sbc2y scc2y sdc2y inflationcrises20pct2y, wmat(dcountry4000) model(sdm) fe durbin(CBIE) dlag(3) time
outreg2 using "${dirreg}/AppTableC7.tex", bdec(3) se tex(fragment) lab
test [Main]L.WCBIE+[Main]L.CBIE+[Wx]CBIE=1
xsmle CBIE IMFPrograms2y CurrencyUnion_pre5y sbc2y scc2y sdc2y inflationcrises20pct2y, wmat(dcountry6000) model(sdm) fe durbin(CBIE) dlag(3) time
outreg2 using "${dirreg}/AppTableC7.tex", bdec(3) se tex(fragment) lab
test [Main]L.WCBIE+[Main]L.CBIE+[Wx]CBIE=1
xsmle CBIE_Variation IMFPrograms2y CurrencyUnion_pre5y sbc2y scc2y sdc2y inflationcrises20pct2y, wmat(dcountry2000) model(sdm) fe durbin(CBIE_Variation) dlag(3) time
outreg2 using "${dirreg}/AppTableC7.tex", bdec(3) se tex(fragment) lab
xsmle CBIE_Variation IMFPrograms2y CurrencyUnion_pre5y sbc2y scc2y sdc2y inflationcrises20pct2y, wmat(dcountry4000) model(sdm) fe durbin(CBIE_Variation) dlag(3) time
outreg2 using "${dirreg}/AppTableC7.tex", bdec(3) se tex(fragment) lab
xsmle CBIE_Variation IMFPrograms2y CurrencyUnion_pre5y sbc2y scc2y sdc2y inflationcrises20pct2y, wmat(dcountry6000) model(sdm) fe durbin(CBIE_Variation) dlag(3) time
outreg2 using "${dirreg}/AppTableC7.tex", bdec(3) se tex(fragment) lab

}
// end regressions